package com.redoor.app.stake.basicdata.hsf.service.impl;

import com.alibaba.boot.hsf.annotation.HSFProvider;
import com.redoor.app.stake.basicdata.model.BaseCharger;
import com.redoor.app.stake.basicdata.model.BaseChargerCriteria;
import com.redoor.app.stake.basicdata.model.constants.BasicDataRedisConstants;
import com.redoor.app.stake.basicdata.service.BaseChargerService;
import com.yotouch.app.stake.hsf.ChargerService;
import com.yotouch.app.stake.hsf.StationService;
import com.yotouch.app.stake.model.Charger;
import com.yotouch.app.stake.model.response.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@HSFProvider(serviceInterface = ChargerService.class, serviceVersion = "5.0.0", serviceGroup = "grp_asset_of_stake", clientTimeout = 600000)
public class ChargerServiceImpl implements ChargerService {

    private static final Logger logger = LoggerFactory.getLogger(ChargerServiceImpl.class) ;

    @Autowired
    private BaseChargerService baseChargerService;

    /**
     * 统计国网枪数量
     * 调用方：
     *     互联互通
     *
     * @return
     */
    public ResponseInt sgccTotalCount(){
        ResponseInt responseInt = new ResponseInt(0, "") ;

        int count = baseChargerService.sgccTotalCount();
        responseInt.setValue(count);

        return responseInt ;
    }

    /**
     * 获取国网枪数据
     * 调用方：
     *     互联互通
     *
     * @param offset
     * @param limit
     * @return
     */
    public ResponseChargerList sgccCharger(int offset, int limit){
        ResponseChargerList rcl = new ResponseChargerList(0, "");
        if(limit >= 100){
            rcl.setErrMsg("list charger size too large , set default size 100") ;
            logger.debug("list charger size too large " + limit); ;
            limit = 100 ;
        }

        List<Charger> chargers = baseChargerService.sgccCharger(offset,limit);
        rcl.setChargerList(chargers);
        return rcl ;
    }

    /**
     * 根据停车区ID获取充电枪列表
     * e充电调用
     *
     * @param parkingAreaUuid
     * @return
     */
    @Override
    public ResponseChargerList listByParkingArea(String parkingAreaUuid) {
        logger.info("parkingAreaUuid："+parkingAreaUuid);
        ResponseChargerList responseChargerList = new ResponseChargerList(0, "") ;
        if (parkingAreaUuid==null || parkingAreaUuid.trim().length()==0){
            responseChargerList.setErrMsg("停车区主键不能为空!");
            return responseChargerList;
        }

        List<Charger> chargers = baseChargerService.listByParkingArea(parkingAreaUuid);
        responseChargerList.setChargerList(chargers);

        return responseChargerList ;
    }

    /**
     * 根据桩编号查询所有枪
     *
     * @param stakeNo
     * @return
     */
    @Override
    public ResponseChargerList listByStakeNo(String stakeNo){
        ResponseChargerList rcl = new ResponseChargerList(0, "") ;
        if (stakeNo==null || stakeNo.trim().length()==0){
            rcl.setErrMsg("桩编号不能为空!");
            return rcl;
        }
        List<Charger> chargers = baseChargerService.listByStakeNo(stakeNo);
        rcl.setChargerList(chargers);
        return rcl ;
    }

    @Override
    public ResponseInt totalCount() {

        ResponseInt rt = new ResponseInt(0, "");
        BaseChargerCriteria criteria = new BaseChargerCriteria();

        int count = baseChargerService.queryChargersTotal(criteria);
        rt.setValue(count);

        return rt;
    }

    @Override
    public ResponseChargerList list(int offset, int limit) {
        ResponseChargerList rcl = new ResponseChargerList(0, "");
        if(limit >= 100){
            rcl.setErrMsg("list charger size too large , set default size 100") ;
            logger.debug("list charger size too large " + limit); ;
            limit = 100 ;
        }

        BaseChargerCriteria criteria = new BaseChargerCriteria();
        criteria.setOffset(offset);
        criteria.setLimit(limit);

        List<Charger> chargers = baseChargerService.hsfChargers(criteria);
        rcl.setChargerList(chargers);

        return rcl;
        
    }

    /**
     * 说明：根据充电站ID获取充电枪数量
     * 调用方：
     *     互联互通
     *
     * @param stationUuid
     * @return
     */
    @Override
    public ResponseInt countByStation(String stationUuid) {
        ResponseInt ri = new ResponseInt(0, "");

        BaseChargerCriteria criteria = new BaseChargerCriteria();
        criteria.setStationUuid(stationUuid);

        int count = baseChargerService.hsfChargersCount(criteria);

        return ri;
    }

    /**
     * 根据站ID获取充电枪列表
     *
     * e充电调用
     * @param stationUuid
     * @param offset
     * @param limit
     * @return
     */
    @Override
    public ResponseChargerList listByStation(String stationUuid, int offset, int limit) {
        ResponseChargerList rcl = new ResponseChargerList(0, "");

        BaseChargerCriteria criteria = new BaseChargerCriteria();
        criteria.setStationUuid(stationUuid);

        List<Charger> list = baseChargerService.hsfChargers(criteria);

        rcl.setChargerList(list);
        return rcl;
    }

    @Override
    public ResponseInt countByMeasureModel(String measureModel) {
        ResponseInt ri = new ResponseInt(0, "");

        return ri;
    }

    @Override
    public ResponseChargerList listByMeasureModel(String measureModel, int offset, int limit) {

        ResponseChargerList rcl = new ResponseChargerList(0, "");


        return rcl;
    }

    @Override
    public ResponseInt countByStationAndMeasureModel(String stationUuid, String measureModel) {
        ResponseInt ri = new ResponseInt(0, "");

        return ri;
    }

    @Override
    public ResponseChargerList listByStationAndMeasureModel(String stationUuid, String measureModel, int offset, int limit) {
        ResponseChargerList rcl = new ResponseChargerList(0, "");

        return rcl;
    }

    @Override
    public ResponseInt countByParking(String parkingUuid) {
        ResponseInt ri = new ResponseInt(0, "");

        BaseChargerCriteria criteria = new BaseChargerCriteria();
        criteria.setSpaceUuid(parkingUuid);

        int count = baseChargerService.hsfChargersCount(criteria);
        ri.setValue(count);
        return ri;
    }

    @Override
    public ResponseChargerList listByParking(String parkingUuid, int offset, int limit) {
        ResponseChargerList rcl = new ResponseChargerList(0, "");

        BaseChargerCriteria criteria = new BaseChargerCriteria();
        criteria.setSpaceUuid(parkingUuid);

        List<Charger> chargers = baseChargerService.hsfChargers(criteria);
        rcl.setChargerList(chargers);
        return rcl;
    }

    @Override
    public ResponseCharger get(String uuid) {
        ResponseCharger rc = new ResponseCharger(0, "");
        if (uuid==null || uuid.trim().length()==0){
            rc.setErrMsg("充电枪主键不能为空!");
            return rc;
        }
        Charger charger = baseChargerService.getChargerHsf(uuid);

        rc.setCharger(charger);
        return rc;
    }

    @Override
    public ResponseCharger get(String equipId, String chargerNo) {
        ResponseCharger rc = new ResponseCharger(0, "");
        if (equipId==null || equipId.trim().length()==0 || chargerNo==null || chargerNo.trim().length()==0){
            rc.setErrMsg("桩编号或枪编号不能为空!");
            return rc;
        }
        Charger charger = baseChargerService.getChargerHsf(equipId,chargerNo);
        rc.setCharger(charger);

        return rc;
        
    }

    @Override
    public ResponseBase set(Charger charger) {

        
        return new ResponseBase(0, "");
    }

    @Override
    public ResponseBoolean checkRegister(String equipId, String registerCode, String authCode, String chargerNo) {

        ResponseBoolean rb = new ResponseBoolean(0, "");
        
        rb.setValue(false);
        return rb;
    }

    @Override
    public boolean initChargerInRedis(int offset, int limit){

        return true;
    }

}
